package com.admin.servlet;

import com.admin.service.IAdminService;
import com.admin.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UpdateBookServlet", value = "/UpdateBookServlet")
public class UpdateBookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        int bookid = Integer.parseInt(request.getParameter("bookid"));
        int number = Integer.parseInt(request.getParameter("number"));
        IAdminService adminService = new AdminServiceImpl();
        if (adminService.updateBookNumber(bookid, number)) {
            request.setAttribute("msg", "书籍修改成功！");

        } else {
            request.setAttribute("msg", "书籍修改失败！");
        }
        String adminname = (String) request.getSession().getAttribute("adminname");
        System.out.println(adminname);
        request.getRequestDispatcher("/BookListServlet?adminname=" + adminname).forward(request, response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
